import { GCellRenderer } from "../../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../../common/ObjCreate";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { ResouceConst } from "../../../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { SGuildGroupPlayer } from "../../../../../../Message/Public/SGuildGroupPlayer";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { Cache } from "../../../../cache/Cache";
import { EGuildGroupPos } from "../../../../../../Message/Public/EGuildGroupPos";
import { HTMLUtil } from "../../../../../../com/gengine/utils/HTMLUtil";
import { CareerUtil } from "../../../common/util/CareerUtil";
import { Language } from "../../../../../../extend/language/Language";
import { DataEvent } from "../../../../events/DataEvent";
import { GModuleEvent } from "../../../../mvc/GModuleEvent";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { ScaleBitmap } from "../../../../../../com/mui/display/ScaleBitmap";
//class GuildEliteGroupMemberRenderer
    
    export  class GuildEliteGroupMemberRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            ObjCreate.createBg(10, 0, 220, 2, this, ImagesConst.SplitLine);
            this._selectedSkin = ResouceConst.getScaleBitmap(ImagesConst.GcellBg);
            this._selectedSkin.width = 240;
            this._selectedSkin.height = 22;
            this._selectedSkin.y = 2;
            this.addChild(this._selectedSkin);
            this._captainIcon = GlobalClass.getBitmap(ImagesConst.GroupCaptainIcon);
            this._captainIcon.x = 7;
            this._captainIcon.y = 5;
            this.addChild(this._captainIcon);
            var loc1=new GTextFormat(FontUtil.defaultName, 12, GlobalStyle.color1Uint);
            this._name = ObjCreate.createGTextField("名字7格子", 25, 3, 100, 20, this, loc1, true);
            this._name.addEventListener(flash.events.TextEvent.LINK, this.onTextLinkHandler);
            this._career = ObjCreate.createGTextField("武圣", 128, 3, 100, 20, this, loc1, true);
            loc1.color = GlobalStyle.color6Uint;
            this._fight = ObjCreate.createGTextField("550000", 167, 3, 100, 20, this, loc1, true);
            this._optBtn = ObjCreate.createGButton("", 215, 3, 19, 19, this, "CloseButtonBlue");
            this._optBtn.drawNow();
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc2=null;
            super.data = arg1;
            var loc1=arg1 as SGuildGroupPlayer;
            if (loc1) 
            {
                this._isMySelf = EntityUtil.equal(Cache.instance.role.entityInfo.entityId, loc1.player.entityId);
                this._isCommander = Cache.instance.guildElite.isGuildGroupCommander(-1, loc1.player.entityId);
                this._isCaptain = loc1.postion == EGuildGroupPos._EGuildGroupCaptain;
                loc2 = GlobalStyle.color1;
                if (this._isCommander) 
                {
                    loc2 = GlobalStyle.color9;
                }
                else if (this._isCaptain) 
                {
                    loc2 = GlobalStyle.color6;
                }
                else if (this._isMySelf) 
                {
                    loc2 = GlobalStyle.color5;
                }
                this._name.htmlText = HTMLUtil.addColor(loc1.player.name, loc2);
                this._career.htmlText = HTMLUtil.addColor(CareerUtil.getCareerName(loc1.player.careerEnable), loc2);
                this._fight.htmlText = HTMLUtil.addColor(String(loc1.player.warfare), loc2);
                if (loc1.postion != EGuildGroupPos._EGuildGroupCaptain) 
                {
                    this._captainIcon.visible = false;
                }
                else 
                {
                    this._captainIcon.visible = true;
                }
                if (this.showKickOutButton()) 
                {
                    this._optBtn.visible = true;
                }
                else 
                {
                    this._optBtn.visible = false;
                }
            }
            else 
            {
                this._name.htmlText = HTMLUtil.addColor("<u><a href=\'event:\'>" + Language.getString(60672) + "</a></u>", GlobalStyle.gray);
                this._career.htmlText = "";
                this._fight.htmlText = "";
                this._optBtn.visible = false;
                this._captainIcon.visible = false;
            }
            return;
        }

        /* internal  */showKickOutButton(): Boolean
        {
            var loc1=data as SGuildGroupPlayer;
            if (loc1 == null) 
            {
                return false;
            }
            if (this._isMySelf) 
            {
                return false;
            }
            var loc2=Cache.instance.guild.isLeaderOrDeputyLeader;
            if (loc2) 
            {
                return true;
            }
            var loc3=Cache.instance.guildElite.isMeYourGroupLeader(loc1.player.entityId);
            if (loc3) 
            {
                return true;
            }
            var loc4;
            if (loc4 = Cache.instance.guildElite.isMeYourTeamLeader(loc1.player.entityId)) 
            {
                return true;
            }
            return false;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            this._selectedSkin.visible = arg1;
            return;
        }

        /* internal  */onButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.GuildGroup_MemberOptBtnClick, {"data": data, "x": arg1.stageX, "y": arg1.stageY}, false, true, true));
            return;
        }

        /* internal  */onTextLinkHandler(arg1: Object /* flash.events.Event */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.GuildGroup_DoEnterGroup, {"data": data, "pos": this.listData.index}, false, true, true));
            return;
        }

        /* internal */ /* var */_captainIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_career: GTextFiled;

        /* internal */ /* var */_fight: GTextFiled;

        /* internal */ /* var */_optBtn: GButton;

        /* internal */ /* var */_selectedSkin: ScaleBitmap;

        /* internal */ /* var */_isMySelf: Boolean;

        /* internal */ /* var */_isCommander: Boolean;

        /* internal */ /* var */_isCaptain: Boolean;
    }
